package cn.net.xyan.easy.webapp.base.entity;

import cn.net.xyan.easy.webapp.base.entity.status.UserStatus;

import javax.persistence.*;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by xiashenpin on 16/1/23.
 */
@Entity
@Table(name = "t_sys_user")
@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(name="type",discriminatorType = DiscriminatorType.STRING)
public class SystemUser {



    String username;
    String password;
    String realName;
    String email;
    List<Permission> permissions = new LinkedList<>();
    List<PermissionGroup> permissionGroups = new LinkedList<>();
    UserStatus status;

    public SystemUser(){

    }

    public SystemUser(String username,String password){
        this.username = username;
        this.password = password;
    }

    @Id
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "password",nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @ManyToMany(cascade={CascadeType.PERSIST})
    @JoinTable(name = "t_sys_user_permission_join")
    public List<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    @ManyToMany(cascade={CascadeType.PERSIST})
    @JoinTable(name = "t_sys_user_permission_group_join")
    public List<PermissionGroup> getPermissionGroups() {
        return permissionGroups;
    }

    public void setPermissionGroups(List<PermissionGroup> permissionGroups) {
        this.permissionGroups = permissionGroups;
    }

    @ManyToOne
    @JoinColumn(name = "status")
    public UserStatus getStatus() {
        return status;
    }

    public void setStatus(UserStatus status) {
        this.status = status;
    }
}
